using UnityEngine; namespace NextMind.Examples.Utility { /// /// This component ensures that the canvas attached to the same GameObject has the set as world Camera. /// [RequireComponent(typeof(Canvas))] public class EnsureWorldCamera : MonoBehaviour { /// /// The canvas attached to the GameObject. /// private Canvas canvas; private void Awake() { canvas = GetComponent(); // If the world camera is null set the main one. if (canvas.worldCamera == null) { canvas.worldCamera = Camera.main; } } } }